
public class Producer<T extends Comparable<T>> extends Prosumer<T> implements Runnable {
    Producer(int id, SyncHeap<T> sHeap, javax.swing.JLabel pLabel, double prodTime, 
            boolean useRandom, boolean printToStd) {
        super(id, sHeap, pLabel, prodTime, useRandom, printToStd);
        m_sH.addProducer();
    }
    @Override
    protected void process() {
	boolean woken = false;
	try {
	    while ((!m_sH.isFull())||(m_sH.nbrConsumers() != 0)) {
                if (m_useRandom) m_processTime = m_rand.nextFloat() * 5000;
		Thread.sleep( (int)(m_processTime) ); //working with producing obj...
		T obj = (T)(produceElement());
		m_sH.addElement(obj); 
                String tempStr = "Producer "+m_id+" (running thread \""+Thread.currentThread().getName()+"\") produced \""+obj+"\""; 
		if (m_printToStd) System.out.println(tempStr);
                m_label.setText(tempStr);
	    }
	}  catch(InterruptedException e) {
	    //Since it sleeps now and then interrupt will work (no need to put any flag)
	    if (m_printToStd) System.out.println("Producer " + m_id + " interrupted while producing an element (sleeping)");
	    m_sH.addElement(m_sH.getPoisson());  //Just to not get a consumer hanging in case of empty heap... 
	    woken = true;
	}
	if ((!woken)&&(m_printToStd)) System.out.println("Producer " + m_id + " interrupted while waiting due to a full heap.");
    }
    protected Object produceElement() { 
        return (Object)( (Integer)( (int)(m_rand.nextFloat() * 100.) ));
    }
}
